<?php
/**
 * beimuaihui System
 * Copyright(c) 2011-2020 beimuaihui.
 * @license    http://www.gnu.org/licenses/gpl.html     This software Under GPL V3 License 
 * beimuaihui@gmail.com
 * http://code.google.com/p/beimuaihui/
 * $Id: Resource.php 311 2011-09-19 03:35:08Z beimuaihui@gmail.com $
 */


Zend_Loader::loadClass("Baogg_Db_Table");

//class Permission extends Baogg_Db_Table {
class Resource  extends Baogg_Db_Table {
	/**
	 * The default table name 
	 */
	protected $_name;
	protected $_db ;
	protected $_primary; 
	
	function __construct() {
		$this->_name =   'resource';
		
		$this->primary= $this->_primary='resource_id';
		parent::__construct();
	}
	
	
	

	function getSame($arr) {	
		$ret=array();
		
	    $sql = "SELECT {$this->primary} FROM {$this->_name} WHERE resource_name ='{$arr['resource_name']}' ";
		//var_dump($arr);var_dump($this->primary); echo $sql;exit();
		$rs = $this->_db->query($sql)->fetchAll();
		foreach((array)$rs as $v)
		{
		    $ret[]=$v[$this->primary];
		}
		return $ret; 	
	
	}
	
	function getResource($item=array()){
		if(!is_array($item) || count($item)<=0){
			return array();
		}
		$table_name=$item['table_name'];
		$col=array("{$item['key_col']} as key_col","{$item['show_col']} as show_col");
		if($item['parent_col']){
			$col[]="{$item['parent_col']} as parent_col";
		}
		$col[]="*";
		$select=$this->_db->select();
		$select->from($table_name,$col);
		
		$rs=$this->_db->fetchAll($select);
		if($item['parent_col']){
			$dbTree=new Baogg_Db_Tree();
			$tr=$dbTree->rs2GridTree($rs);
			$rs=$dbTree->tr2GridStore($tr);
		}
		
		foreach((array)$rs as $k=>$v){
			if($item['table_name']=='menu'){
				$rs[$k]['is_resourced']=$v['url']?1:0;
				$rs[$k]['is_oped']=$v['url'] ?1:0; //&& $v['is_page']
			}else{
				$rs[$k]['is_resourced']=1;
				$rs[$k]['is_oped']=1;
			}
		}

		return $rs;
	}
	
	


}
